package com.group4.datafactorybackend.common.enums;


import com.group4.datafactorybackend.common.R;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lichuandong
 * @date 2021/1/5
 * @description 返回值枚举类
 */
@SuppressWarnings("AlibabaEnumConstantsMustHaveComment")
public enum ResultCodeEnum {

    SUCCESS(100200, "返回成功"),
    SYSTEM_EXCEPTION(100500, "系统异常"),
    REQUEST_PARAM_ERROR(100401,"请求参数错误"),
    REQUEST_OUT_OVERTIME(100408,"请求超时"),
    REQUEST_NOT_FOUND(100404,"请求的资源或服务未找到"),
    REQUEST_LENGTH_LIMIT(100414,"请求URI太长"),
    REQUEST_Format_NOT_SUPPORTED(100415,"请求的格式不支持"),
    TOKEN_EXPIRED_REDIRECT(100302,"token过期,请重新登录"),


    INTERFACE_BASIC_INFORMATION_NULL(100001, "接口基本信息为空"),
    INTERFACE_NAME_NULL(100002, "接口名称为空"),
    INTERFACE_SOURCE_NULL(100005, "接口来源为空"),
    INTERFACE_PROTOCOL_NULL(100003, "接口协议为空"),
    INTERFACE_NOT_ENABLED(100123, "接口未启用"),
    INTERFACE_IP_PORT_NULL(100012, "ip和端口为空"),
    INTERFACE_PATH_NULL(100004, "接口路径为空"),
    INTERFACE_REQUEST_METHOD_NULL(100008, "接口请求方式"),
    REQUEST_TIMEOUT(100014, "超时时限为空"),
    REQUEST_PARAM_NULL(100012, "请求参数为空"),
    INTERFACE_BASE_NOT_FOUND(100013, "未找到该条接口基本信息"),
    INTERFACE_SETTING_NOT_FOUND(100015, "未找到该条接口配置信息"),
    INTERFACE_BASE_EXIST(100026, "接口基本信息已存在"),
    INTERFACE_BASE_NOT_EXIST(100025, "接口基本信息不存在"),
    INTERFACE_SETTING_EXIST(100027, "接口配置信息已存在"),
    INTERFACE_SETTING_NOT_EXIST(100028, "接口配置信息不存在"),
    INTERFACE_PATH_ILLEGAL(100009, "接口路径不符合规范"),
    REQUIRED_FIELD_IS_BLANK(100007, "入参必填字段为空： "),
    REQUEST_OUT_API_FAIL(100018, "请求外部接口失败，返回状态码："),
    REQUEST_OUT_GET_OVERTIME(100019, "GET请求外部接口失败，请求超时"),
    REQUEST_OUT_POST_OVERTIME(100020, "POST请求外部接口失败，请求超时"),
    REQUEST_OUT_PUT_OVERTIME(100021, "PUT请求外部接口失败，请求超时"),
    REQUEST_OUT_DELETE_OVERTIME(100022, "DELETE请求外部接口失败，请求超时"),
    OTHER_METHODS_NOT_SUPPORTED(100023, "现阶段不支持其他请求方式"),
    PARAM_BODY_CONTENT_ERROR(100024, "请求body不是json格式"),
    SPLICING_PARAM_IS_FAIL(100031, "拼接GET请求入参出错，请检查参数"),

    /** 自定义返回值枚举值 **/
    OPERATION_SUCCESS(400200,"操作成功"),
    CONNECT_TEST_SUCCESS(400230, "连通测试成功"),
    CONNECT_TEST_FAILED(400430,"连通测试失败"),

    OPERATION_FAILED(400400,"操作失败"),

    VERIFY_DATA_FAILED(400600, "数据校验失败"),

    EXIST_NOT_RELEASE(400401,"存在未发布"),
    EXIST_HAVE_RELEASE(400402,"存在已发布"),

    EXIST_DATA_ASSERT(400406,"新增资产目录失败，此目录下存在资产表"),
    EXIST_CHILD_DIRECTORY(400407,"删除失败，存在子目录"),
    EXIST_API(400408,"删除失败，存在接口"),

    BEING_CITED(400410,"正在被引用中"),

    DATA_EXIST(400430,"数据已存在"),

    STOPWATCH_NAME_EXIST(4004015,"码表名称重复"),
    STOPWATCH_ENCODING_IS_NULL(400420,"码表配置项为空"),
    SAME_LEVEL_DIRECTORY_NAME_REPEAT(400416,"目录名称与同级目录重名"),
    SAME_PATH_DIRECTORY_NAME_REPEAT(400417,"目录名称与同路径目录重名"),
    DATA_SOURCE_NAME_REPEAT(400418,"数据源名称重复"),
    DATA_SOURCE_JDBC_URL_REPEAT(400419,"数据源连接信息重复"),
    ENCODING_CONFIGURATION_VALUE_REPEAT(400420,"码值取值重复"),
    ENCODING_CONFIGURATION_NAME_REPEAT(400421,"码值名称重复"),
    CN_NAME_REPEAT(400422,"中文名称重复"),
    EN_NAME_REPEAT(400423,"英文名称重复"),

    /** 表格操作 **/
    EXCEL_EXPORT_FAILED(400157,"导出表格失败"),
    EXCEL_IMPORT_FAILED(400159,"导入表格失败"),
   ;

    /**
     * 枚举值
     */
    private final Integer code;

    /**
     * 枚举描述
     */
    private final String message;

    /**
     * 构造一个<code>LocalCacheEnum</code>枚举对象
     *
     * @param code 枚举值
     * @param message 枚举描述
     */
    ResultCodeEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }
    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public <T> R<T> result(){
        return new R(getCode(),getMessage());
    }
    public <T>  R<T> result(String message){
        return new R(getCode(),message);
    }
    /**将返回码标准的信息 填充到message里面，message必须包含一个%s*/
    public <T>  R<T> resultFillingMessage(String message){
        return new R(getCode(),String.format(message,getMessage()));
    }


    /**将message添加到返回码标准的信息后面 再返回{@link R}*/
    public <T> R<T> resultAppendMessage(String message){
        return new R(getCode(),getMessage()+message);
    }



    /**
     * 获取全部枚举
     *
     * @return List<LocalCacheEnum>
     */
    public static List<ResultCodeEnum> getAllEnum() {
        List<ResultCodeEnum> list = new ArrayList<>();
        for (ResultCodeEnum each : values()) {
            list.add(each);
        }
        return list;
    }

    /**
     * 获取全部枚举值
     *
     * @return List<String>
     */
    public static List<Integer> getAllEnumCode() {
        List<Integer> list = new ArrayList<>();
        for (ResultCodeEnum each : values()) {
            list.add(each.code);
        }
        return list;
    }
}
